<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>供应商信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <div class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">销售编号</label>
                            <div class="layui-input-inline">
                                <input id="logid" type="text" name="logid" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-inline">
                                <input id="cname" type="text" name="cname" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <input id="state" type="text" name="state" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>


    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../../../jquery-3.3.1.js" charset="UTF-8"></script>
<script>

    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        function add0(m){
            return m<10?'0'+m:m
        }


        table.render({
            elem: '#currentTableId',
            url: '/log/commoditylogList',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {width:80},
                {field: 'logid', width: 120, title: '销售编号', sort: true},
                {field: 'cname', minwidth: 90, title: '名称'},
                {field: 'price', minwidth: 90, title: '进价',templet:function(d){
                    return (d.price/d.scale).toFixed(2)+"元/"+d.mlittle
                    }},
                {field: 'sprice', minwidth: 90, title: '售价',templet:function (d) {
                        return d.sprice+"元/"+d.mlittle
                    }},
                {field: 'count',minwidth: 200, title: '数量',templet:function (d) {
                        return d.count+d.mlittle
                    }},
                {field: 'total',minwidth: 200, title: '共计',templet:function (d) {
                        return (d.count*d.sprice).toFixed(2)+"元"
                    }},
                {field: 'hiredate', minwidth: 200, title: '变动时间',templet:function (d) {
                        var time = new Date(d.hiredate);
                        var y = time.getFullYear();
                        var m = time.getMonth()+1;
                        var d = time.getDate();
                        return y+'-'+add0(m)+'-'+add0(d);
                    }},
                {field: 'state', minwidth: 200, title: '状态',templet:function (d) {
                        if (d.state===0){
                            return "售出"
                        }else if (d.state==1){
                            return "退回"
                        }
                    }}
            ]], page:true,
            limits: [5,10, 15]
            , limit: 10
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                var result;
                if (this.page.curr) {
                    result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
                }
                else {
                    result = res.data.slice(0, this.limit);
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": result //解析数据列表
                };
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    logid:$("#logid").val(),
                    cname:$("cname").val(),
                    state:$("#state").val()
                }
            }, 'data');
            return false;
        });

    });
</script>

</body>
</html>